package org.jjj.basic.service.impl;

import org.jjj.basic.service.IFastDfsService;
import org.jjj.basic.utils.FastdfsUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class FastDfsServiceImpl implements IFastDfsService {
    //获取配置文件中的参数
    @Value("${fastdfs.url}")
    private String fastDfsUrl;
    @Override
    public String upload(byte[] bytes, String extName) {

        return fastDfsUrl+ FastdfsUtil.upload(bytes,extName);
    }

    /**
     * 删除文件的逻辑
     * @param path
     */
    @Override
    public void delete(String path) {
        //前端传来的path:http://115.159.217.249:8888/group1/M00/00/08/rBEAA2NjPoCARvPJAAGPVPo2nEA55.jpeg
        path = path.substring(fastDfsUrl.length()+1);
        int i = path.indexOf("/");//取得第一个/处的索引值
        String groupName = path.substring(0, i);
        String fileName = path.substring(i+1);
        FastdfsUtil.delete(groupName,fileName);
    }
}
